#include "uptime.h"
#include <sys/sysinfo.h>
#include <iostream>

void print_uptime() {
    struct sysinfo s_info;
    if (sysinfo(&s_info) == 0) {
        int uptime_seconds = s_info.uptime;
        int days = uptime_seconds / (60 * 60 * 24);
        int hours = (uptime_seconds / (60 * 60)) % 24;
        int minutes = (uptime_seconds / 60) % 60;
        if (days > 0) {
            std::cout << "Uptime: " << days << " days, ";
        }
        if (hours == 1) {
            std::cout << hours << " hour, ";
        } else {
            std::cout << hours << " hours, ";
        }
        if (minutes == 1) {
            std::cout << minutes << " minute" << std::endl;
        } else {
            std::cout << minutes << " minutes" << std::endl;
        }
    } else {
        std::cout << "Error getting system uptime" << std::endl;
    }
}
